package com.springbootdemo.demo.mail;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 发送简单邮件
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class SimpleEmailTest {


    @Autowired
    private Environment environment;
    @Autowired
    private JavaMailSender mailSender;


    @Test
    public void sendSimpleMail(){

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(environment.getProperty("spring.mail.username"));
        //simpleMailMessage.setTo("15712058302@163.com");
        simpleMailMessage.setTo("wyzshiwu@163.com");
        simpleMailMessage.setSubject("测试");
        simpleMailMessage.setText("前子给你发个邮件！！");
        mailSender.send(simpleMailMessage);


    }

}
